import { request } from './index'

// 获得user首页数据
export function GetUser (data: {query: string, pagenum: number, pagesize: number}) {
  return request({
    url: `/users?query=${data.query}&pagenum=${data.pagenum}&pagesize=${data.pagesize}`,
    method: 'get'
  })
}

// 添加用户
export function AddUserFnc (data: {username: string, password: string, email: string, mobile: string}) { // 添加用户
  return request({
    url: '/users',
    method: 'post',
    data: data
  })
}

// 打开修改盒子 获取对应的user信息
export function GetUserInfoFnc (id: number) { 
  return request({
    url: `/users/${id}`,
    method: 'get'
  })
}

// 修改用户
export function EditUserFnc (id: number, data: any) { 
  return request({
    url: `/users/${id}`,
    method: 'put',
    data: data
  })
}



// 更改switch 状态
export function ChangeSwitchFnc (data: {id: number, state: boolean}) { 
  return request({
    url: `users/${data.id}/state/${data.state}`,
    method: 'put'
  })
}

// 删除用户
export function RemoveUserFnc (id: number) { 
  return request({
    url: `/users/${id}`,
    method: 'delete'
  })
}

// 打开分配角色盒子 获取对应的角色信息
export function GetRolesFnc () { 
  return request({
    url: '/roles',
    method: 'get'
  })
}

// 保存角色分配
export function SaveRolesFnc (id: number, data: any) { 
  return request({
    url: `/users/${id}/role`,
    method: 'put',
    data: data
  })
}